﻿Public Class OptionButton
    Inherits Windows.Forms.RadioButton

    Event Change(ByVal sender As Object)

    Dim NoEvents As Boolean
    Dim InitialChecked As Boolean
    Dim m_Source As Object
    Dim m_UseEnterAsTab As Boolean
    Dim m_BoundLabel As Label
    Dim m_IsRequired As Boolean
    Dim m_Label As Label

    Overrides Property MinimumSize() As System.Drawing.Size
        Get
            Return New Size(1, 23)
        End Get
        Set(ByVal Value As System.Drawing.Size)
            MyBase.MinimumSize = Value
        End Set
    End Property

    Overrides Property MaximumSize() As System.Drawing.Size
        Get
            Return New Size(10000, 23)
        End Get
        Set(ByVal Value As System.Drawing.Size)
            MyBase.MaximumSize = Value
        End Set
    End Property

    Public WriteOnly Property Active() As Boolean
        Set(ByVal Value As Boolean)
            'BackColor = If(Value, SystemColors.Window, SystemColors.Control)
        End Set
    End Property

    Public Property Value() As Boolean
        Get
            Return Checked
        End Get
        Set(ByVal Value As Boolean)
            Checked = Value
        End Set
    End Property

    ReadOnly Property IsDirty() As Boolean
        Get
            Return Checked <> InitialChecked
        End Get
    End Property

    Property UseEnterAsTab() As Boolean
        Get
            Return m_UseEnterAsTab
        End Get
        Set(ByVal Value As Boolean)
            m_UseEnterAsTab = Value
        End Set
    End Property

    Public Sub New()
    End Sub

    Property [ReadOnly]() As Boolean
        Get
            Return Enabled
        End Get
        Set(ByVal Value As Boolean)
            Enabled = Not Value
        End Set
    End Property

    Public ReadOnly Property IsEmpty() As Boolean
        Get
            Return False
        End Get
    End Property

    Property IsRequired() As Boolean
        Get
            Return m_IsRequired
        End Get
        Set(ByVal Value As Boolean)
            m_IsRequired = Value
        End Set
    End Property

    Dim m_ColSpan As Integer = 1
    Property ColSpan() As Integer
        Get
            Return m_ColSpan
        End Get
        Set(ByVal Value As Integer)
            m_ColSpan = Value
        End Set
    End Property

    Property Label() As Label
        Get
            Return m_Label
        End Get
        Set(ByVal Value As Label)
            m_Label = Value
        End Set
    End Property

    Private Sub CheckBox_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.CheckedChanged
        RaiseEvent Change(Me)
    End Sub

    Private Sub CheckBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Enter
        InitialChecked = Checked
    End Sub

    Private Sub CheckBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        If m_UseEnterAsTab Then
            If e.KeyChar = Chr(13) Then
                e.Handled = True
                SendKeys.Send("{TAB}")
                Exit Sub
            End If
        End If
    End Sub

    Dim m_Caption As String
    Property Caption() As String
        Get
            Return m_Caption
        End Get
        Set(ByVal Value As String)
            m_Caption = Value
        End Set
    End Property

    Public ReadOnly Property Errors() As String
        Get
            If IsRequired AndAlso IsEmpty Then Return Caption & " alanı boş olamaz."
            Return ""
        End Get
    End Property

    Property BoundLabel() As Label
        Get
            Return m_BoundLabel
        End Get
        Set(ByVal Value As Label)
            m_BoundLabel = Value
        End Set
    End Property

End Class
